package com.yycwxt.modules.admin.subject;

import com.yycwxt.common.ReturnResult;
import com.yycwxt.domain.Subject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@Validated
@RequestMapping("/subject")
public class  SubjectController {

    private final SubjectService subjectService;

    public SubjectController(@Autowired SubjectService subjectService){
        this.subjectService = subjectService;
    }

    @PostMapping()
    @ApiOperation("新增科目信息")
    public ReturnResult insert(@ApiParam(name = "科目信息", required = true, type = "Subject") @RequestBody @Validated Subject subject) {
        return ReturnResult.buildSuccessResult(subjectService.insert(subject));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除指定id的科目信息")
    public ReturnResult deleteById(@ApiParam(name = "id", required = true, type = "Integer") @PathVariable Integer id) {
        return ReturnResult.buildSuccessResult(subjectService.removeById(id));
    }


    @PostMapping("/update")
    @ApiOperation("修改指定id的科目信息")
    public ReturnResult updateById(@ApiParam(name = "科目信息", required = true, type = "subject")@Validated @RequestBody  Subject subject ) {
        return ReturnResult.buildSuccessResult(subjectService.update(subject));
    }


    @GetMapping("/selectByInput")
    @ApiOperation("根据输入条件进行全文检索")
    public ReturnResult selectByInput(@ApiParam(name = "input检索内容", required = true, type = "String") String input){
        return ReturnResult.buildSuccessResult(subjectService.selectByInput(input));
    }

    @GetMapping("/selectAll")
    @ApiOperation("查询全部科目信息")
    public ReturnResult selectAll(){
        return ReturnResult.buildSuccessResult(subjectService.selectAll());
    }
}
